Skip to content

fix(adk): avoid cancel context races in concurrent ChatModelAgent runs - #1185

Open
LPX-E5BD8 wants to merge 2 commits into
cloudwego:mainfrom
LPX-E5BD8:fix-chatmodelagent-cancelctx-race
Open

fix(adk): avoid cancel context races in concurrent ChatModelAgent runs#1185
LPX-E5BD8 wants to merge 2 commits into
cloudwego:mainfrom
LPX-E5BD8:fix-chatmodelagent-cancelctx-race

Conversation

@LPX-E5BD8

Copy link
Copy Markdown

Fixes #1177

concurrent Run on one ChatModelAgent races on reactConfig.cancelCtx.
copy the config per run before writing cancelCtx.

Copilot AI lite review requested due to automatic review settings August 14, 2026 12:08
@CLAassistant

CLAassistant commented Aug 14, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a data race when a long-lived ChatModelAgent is used concurrently on the tools/ReAct execution path by ensuring per-run cancellation state is written to a per-run config copy rather than mutating a shared reactConfig / modelWrapperConf.

Changes:

  • Copy reactConfig (and modelWrapperConf when present) inside each Run closure before injecting cancelCtx, avoiding shared mutable state across concurrent runs.
  • Apply the same per-run config copy approach to both message-based and agentic ReAct run functions.
  • Add a concurrent regression test that exercises concurrent Run calls on a shared agent with tools enabled.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
adk/chatmodel.go Avoids concurrent mutation of shared ReAct config by shallow-copying configs per run before setting cancel state.
adk/chatmodel_concurrent_test.go Adds a concurrency regression test covering shared-agent concurrent runs on the tools/ReAct path.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@LPX-E5BD8 LPX-E5BD8 changed the title fix chatmodelagent race on shared cancelCtx fix(adk): avoid cancel context races in concurrent ChatModelAgent runs Aug 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

adk: data race on shared reactConfig.cancelCtx when concurrent Run reuses one ChatModelAgent (tools/ReAct path)

3 participants